package com.bw.zg2.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

/**
 *
 * @ClassName: BaseActivity
 * @Description:
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/12 11:13 AM
 * @Version: 1.0
 */
abstract class BaseViewBindingActivity< D : ViewDataBinding>(private val layoutId: Int) :
    AppCompatActivity() {

    protected lateinit var dataBinding: D
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        dataBinding = DataBindingUtil.setContentView(this, layoutId)
        dataBinding.lifecycleOwner = this


        initView(savedInstanceState)
        initData()

    }

    abstract fun initData()

    abstract fun initView(savedInstanceState: Bundle?)


    override fun onDestroy() {
        super.onDestroy()
        //防止内存泄漏
        if (dataBinding != null) {
            dataBinding.unbind()
        }
    }

}